{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-05-30T20:50:02.745565Z",
     "start_time": "2017-05-30T20:50:01.307517Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-05-12T23:11:22.793324Z",
     "start_time": "2017-05-12T23:11:22.644586Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5, 2, 3)\n",
      "[[[21 22 23]]]\n",
      "[[[31 32]]\n",
      "\n",
      " [[41 42]]\n",
      "\n",
      " [[51 52]]]\n",
      "[[[12]]\n",
      "\n",
      " [[22]]\n",
      "\n",
      " [[32]]\n",
      "\n",
      " [[42]]]\n",
      "[]\n"
     ]
    }
   ],
   "source": [
    "input = [\n",
    "    [[11, 12, 13], [14, 15, 16]],\n",
    "    [[21, 22, 23], [24, 25, 26]],\n",
    "    [[31, 32, 33], [34, 35, 36]],\n",
    "    [[41, 42, 43], [44, 45, 46]],\n",
    "    [[51, 52, 53], [54, 55, 56]],\n",
    "    ]\n",
    "print(np.asarray(input).shape)\n",
    "s1 = tf.slice(input, [1, 0, 0], [1, 1, 3])\n",
    "s2 = tf.slice(input, [2, 0, 0], [3, 1, 2])\n",
    "s3 = tf.slice(input, [0, 0, 1], [4, 1, 1])\n",
    "s4 = tf.slice(input, [0, 0, 1], [1, 0, 1])\n",
    "s5 = tf.slice(input, [2, 0, 2], [-1, -1, -1]) # negative value means the function cutting tersors automatically\n",
    "tf.global_variables_initializer()\n",
    "with tf.Session() as s:\n",
    "    print (s.run(s1))\n",
    "    print (s.run(s2))\n",
    "    print (s.run(s3))\n",
    "    print (s.run(s4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-05-30T20:56:22.381435Z",
     "start_time": "2017-05-30T20:56:22.351022Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3, 5)\n",
      "[[1, 2, 3, 4, 5], [11, 22, 33, 44, 55], [111, 222, 333, 444, 555]]\n",
      "[[  1   2]\n",
      " [ 11  22]\n",
      " [111 222]]\n"
     ]
    }
   ],
   "source": [
    "input = [[1,  2,  3,  4,  5 ], \n",
    "         [11, 22, 33, 44, 55], \n",
    "         [111, 222, 333, 444, 555]]    \n",
    "    \n",
    "print(np.asarray(input).shape)\n",
    "print(input)\n",
    "s1 = tf.slice(input, [0, 0], [-1,2])\n",
    "\n",
    "tf.global_variables_initializer()\n",
    "with tf.Session() as s:\n",
    "    print (s.run(s1))"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda env:p3]",
   "language": "python",
   "name": "conda-env-p3-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
